package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Validated
@RequestMapping("/operation/serve")
@RestController
@RequiredArgsConstructor
public class ServeController {
    private final IServeService serveService;
    @GetMapping("/page")
    PageResult<ServeResDTO> page(ServePageQueryReqDTO dto){
        return serveService.page(dto);
    }
    @PostMapping("/batch")
    public Result add(@RequestBody List<ServeUpsertReqDTO> dtoList){
        serveService.add(dtoList);
        return Result.ok();
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable Long id, @RequestParam("price") BigDecimal price){
        serveService.update(id, price);
        return Result.ok();
    }
    @PutMapping("/onSale/{id}")
    public Result onSale(@PathVariable Long id){
        serveService.onSale(id);
        return Result.ok();
    }

}
